﻿@model Orchard.Core.Navigation.ViewModels.MenuWidgetViewModel

@using Orchard.ContentManagement

@{
    var selectedMenuId = -1;
}

<fieldset>
    @Html.LabelFor(m => m.CurrentMenuId, T("For Menu"))
    <select id="@Html.FieldIdFor(m => m.CurrentMenuId)" name="@Html.FieldNameFor(m => m.CurrentMenuId)">
    @foreach(ContentItem menu in Model.Menus) {
        @Html.SelectOption(Model.CurrentMenuId, menu.Id, Html.ItemDisplayText(menu, false).ToString())
        if (Model.CurrentMenuId == menu.Id) {
            selectedMenuId = menu.Id;
        }
    }
    </select>
    @if (selectedMenuId != -1) {
        @Html.ActionLink(T("Edit Menu").Text, "Index", new { area = "Navigation", menuId = selectedMenuId }, new { id = "editMenuLink" })
    }
    <span class="hint">@T("Select which menu you want to display")</span>
</fieldset>

<fieldset>
    <label for="@Html.FieldIdFor(m => m.StartLevel)">@T("Start Level")</label>
    @Html.TextBoxFor(m => m.StartLevel, new { @class = "text small" })
    <span class="hint">@T("The level the menu should start at.")</span>
</fieldset>

<fieldset>
    <label for="@Html.FieldIdFor(m => m.StopLevel)">@T("Levels to display")</label>
    @Html.TextBoxFor(m => m.StopLevel, new { @class = "text small" })
    <span class="hint">@T("The number of levels to display, \"0\" meaning all levels.")</span>
</fieldset>

<fieldset>
    @Html.EditorFor(m => m.Breadcrumb) 
    <label class="forcheckbox" for="@Html.FieldIdFor(m => m.Breadcrumb)">@T("Display as Breadcrumb")</label>
    <span class="hint">@T("Check to render the path to the current content item.")</span>
</fieldset>

<div data-controllerid="@Html.FieldIdFor(m => m.Breadcrumb)">
    <fieldset>
        @Html.EditorFor(m => m.AddHomePage) 
        <label class="forcheckbox" for="@Html.FieldIdFor(m => m.AddHomePage)">@T("Add the home page as the first element")</label>
        <span class="hint">@T("Check to render the home page as the first element of the breadcrumb.")</span>
    </fieldset>

    <fieldset>
        @Html.EditorFor(m => m.AddCurrentPage) 
        <label class="forcheckbox" for="@Html.FieldIdFor(m => m.AddCurrentPage)">@T("Add the current content item as the last element")</label>
        <span class="hint">@T("Check to render the current content item as the last element.")</span>
    </fieldset>
</div>

<fieldset>
    @Html.EditorFor(m => m.ShowFullMenu) 
    <label class="forcheckbox" for="@Html.FieldIdFor(m => m.ShowFullMenu)">@T("No filter on selected page")</label>
    <span class="hint">@T("Check for the menu to be displayed without filtering the selected current page.")</span>
</fieldset>

@using (Script.Foot()) {
    <script type="text/javascript">
        (function($) {
            $("#@Html.FieldIdFor(m => m.CurrentMenuId)").change(function (sender) {
                var selected = $(this).val();

                var anchor = $("#editMenuLink");
                var url = anchor.attr("href");
                // Now I need to replace the last part of the url (menuId = ###).
                var newUrl = url.substr(0, url.lastIndexOf("?") + 1);
                newUrl = newUrl + "menuId=" + selected;
                anchor.attr("href", newUrl);
            });
        })(jQuery);
    </script>
}